<template>
  <el-card class="box-card" :style="style">
    <div slot="header" class="clearfix">
      <span>超管-登录</span>
    </div>
    <el-form label-width="60px" :rules="rules" :model="logoData" ref="login">
      <el-form-item label="账号" prop="username">
        <el-input v-model="logoData.username" style="width: 240px" type="text"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="passwd">
        <el-input v-model="logoData.passwd" style="width: 240px" type="password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" style="width: 240px" @click="login" :loading="loading">登录</el-button>
      </el-form-item>
      <el-alert v-if="showMsg" :title="msg" :type="msgType" show-icon></el-alert>
      <slot name="default"></slot>
    </el-form>
  </el-card>
</template>

<script>
// import Cookie from "js-cookie";
// import { superAdminLogin } from "../../server/index";

export default {
  name: "superLogin",
  data() {
    return {
      loading: false,
      showMsg: false,
      msg: "",
      msgType: "success",
      logoData: {
        username: "",
        passwd: ""
      },
      rules: {
        username: [
          {
            required: true,
            message: "请输入账号，格式为邮箱地址",
            trigger: "blur"
          }
        ],
        passwd: [{ required: true, message: "请输入密码", trigger: "blur" }]
      }
    };
  },
  props: {
    width: {
      default: "360px"
    },
    url: {
      type: String,
      default: "Admin/account/login"
    },
    go: {
      type: String,
      default: "home"
    }
  },
  computed: {
    style() {
      return {
        width: this.width
      };
    }
  },
  methods: {
    login() {
      const _this = this;
      _this.$refs["login"].validate(valid => {
        if (valid) {
          _this.loading = true;
          // Cookie.set('Token',_this.logoData.username)
          // superAdminLogin({
          //   account: _this.logoData.username,
          //   password: _this.logoData.passwd
          // }).then(res => {
          //   _this.showMsg = true;
          //   // Cookie.set('Token',res.data.data.token)
          //   // setTimeout(() => {
          //   //     _this.loading = false
          //   //     _this.$router.push({
          //   //         name: _this.go
          //   //     })
          //   // }, 1500)
          //   if (res.data.status == 1) {
          //     Cookie.set("Token", res.data.data.token);
          //     _this.msg = res.data.msg;
          //     setTimeout(() => {
          //       _this.loading = false;
          //       _this.$router.push({
          //         name: _this.go
          //       });
          //     }, 1500);
          //   } else {
          //     _this.msg = res.data.message;
          //     _this.logoData.passwd = "";
          //     _this.msgType = "error";
          //     _this.loading = false;
          //     setTimeout(() => {
          //       _this.showMsg = false;
          //     }, 5000);
          //   }
          // });
        } else {
          return false;
        }
      });
    }
  }
};
</script>

<style scoped>
</style>